<!doctype html>

<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<?php
include_once('navbar.php');
include_once('superheader.php');
?>

<script>
$(function() {
	
	$( "#subset" ).buttonset();
    $( "#datepicker" ).datepicker();
    $( "#datepicker2" ).datepicker();
    $( "#button5" ).button();
    $("#response").html("");
        
 
});
</script>
</head>
<?php
        $m = new Mongo();
        $db = $m->EMU;
        $collection = $db->requests;
		$num = (int)$_GET["requestnum"];
        $cursor = $collection->findOne(array('ticketNum'=> $num));
		//print_r($cursor);
		$assign = $cursor['assignee'];
		$stat = $cursor['status'];
?>
<body>

	<h2>Edit Request:</h2>
	<?php if(isset($_GET["error"])) : ?>
		
		<?php if($_GET["error"] == 'modDate') : ?>
		    <div class="ui-widget">
				<p>Please enter a scheduled date that would not require time travel to be completed on time.</p>
			</div>
		<?php endif; ?>
		
		<?php if($_GET["error"] == 'duplicateEquip') : ?>
		    <div class="ui-widget">
				<p>A maintenance request with that barcode already exists.</p>
			</div>
		<?php endif; ?>
		
		<?php if($_GET["error"] == 'dateEquip') : ?>
		    <div class="ui-widget">
				<p>You cannot schedule a maintenance for a date prior than today.</p>
			</div>
		<?php endif; ?>
		
	<?php endif; ?>
	
	<form action="phpfunctions/updateRequest.php" method="post">
	 	<p>Maintenance Request Description:</p>
	 	
	 	<p><input type="hidden" name="ticketNum" value="<?php echo $cursor["ticketNum"] ?>"></p>
	 	<p><input type="hidden" name="requester" value="<?php echo $cursor["requester"] ?>"></p>
	 	<p><input type="hidden" name="subDate" value="<?php echo $cursor["subDate"] ?>"></p>
	 	<p><input type="hidden" name="status" value="<?php echo $cursor["status"] ?>"></p>
	 	<textarea name="mDescription" cols="40" rows="7"><?php echo $cursor["mDescription"] ?></textarea>
	 	<p>Scheduled Date: <input type="text" name="schedDate" id="datepicker" value="<?php echo $cursor["schedDate"] ?>" />click to pick date</p>
	 	<p>Assignee: 
	 	<select name="assignee">
	 		<?php
		        $z = new Mongo();
		        $db = $z->EMU;
		        $collection = $db->users;
				$newCursor = $collection->find();

				foreach ($newCursor as $item) 
				{
					if ($assign == $item['user'])
					{
						print "<option selected>";
						print $item['user'];
						print "</option>";
					}
					else 
					{
						print "<option>";
						print $item['user'];
						print "</option>";
					}
				}
			?>
	 	</select></p>
	 	<p>Status: 
		 	<select name="status">
		 		<?php
		 			if ($stat == "In Progress")
		 			{
		 				print "<option>Open</option>";
		 				print "<option selected>In Progress</option>";
						print "<option>Closed</option>";
		 			}
					else 
					{
						print "<option>Open</option>";
		 				print "<option>In Progress</option>";
						print "<option>Closed</option>";
					}
		 		?>
		 	</select>	
	 	</p>
	 	<br/>
	 	<button id="button5" input type="submit" name="submit" value="Submit me!" />Submit</button>
	</form>
	
</body>

</html>